<template>
	<div class="app-container">
		<jk-operation-card ref="box1" class="margin-bottom-10">
			<div class="flex-between-center-wrap">
				<div class="flex-start-center-wrap">
					<el-radio-group v-model="searchParams.type" size="small" @change="onSearchBtn">
						<el-radio-button
							v-for="(item) in typeList"
							:key="item.id"
							:label="item.id"
						>{{ item.name }}</el-radio-button>
					</el-radio-group>
				</div>
				<div class="flex-end-center-wrap">
					<!--<jk-select v-model="searchParams.auditState" :option-list="auditStateList" placeholder="状态" clearable class="search-bar-item-size1 margin-5-0 item-gap"></jk-select>-->
					<jk-search-input v-model="searchParams.totalTime" :placeholder="setPh(searchParams.type)" size="small" class="search-bar-item-size2 margin-5-0 item-gap" clearable @on-enter="onSearchBtn" />
					<jk-search-button @click="onSearchBtn"></jk-search-button>
				</div>
			</div>
		</jk-operation-card>

		<jk-card>
			<jk-table ref="jkTable" :loading="tableLoading" :data="tableData" :height="tableHeight + 20">
				<vxe-column
					v-for="(item, index) in tableColumnList"
					:key="index"
					:title="item.title"
					:align="item.align"
					:field="item.keyName"
					:sortable="item.sortable"
					:fixed="item.fixed ? item.fixed : ''"
					:min-width="item.minWidth"
					:width="item.width"
				>
					<template slot-scope="scope">
						<jk-common-status v-if="item.keyName === 'auditState'" :status="scope.row.auditState"></jk-common-status>
						<div v-else-if="item.keyName === 'SpindelInfo'" class="flex-start-center-wrap">
							<div
								v-for="(childItem, childIndex) in scope.row.SpindelInfo"
								:key="childIndex"
								style="margin: 4px;display: flex;flex-direction: column;justify-content: center;align-items: center;border: solid 1px #91d5ff;width: 100px;border-radius: 4px;overflow: hidden;font-size: 13px;"
							>
								<div style="border-bottom: solid 1px #91d5ff;width: 100%;display: flex;justify-content: center;align-items: center;font-weight: 500;background: #e6f7ff;">{{ childItem.SpindleName }}</div>
								<span>{{ childItem.Info }}</span>
							</div>
						</div>
						<span v-else>{{ scope.row[item.keyName] }}</span>
					</template>
				</vxe-column>
			</jk-table>

			<!-- 分页组件 -->
			<!--<footer ref="box2" class="flex-end-center margin-top-10">
				<jk-page
					:page-index="searchParams.pageNo"
					:page-sizes="searchParams.pageSizes"
					:page-size="searchParams.pageSize"
					:total="searchParams.count"
					@on-change="onPageChange"
				/>
			</footer>-->
		</jk-card>
	</div>
</template>

<script>
    import { auditStateList } from '@/utils/jk/status-option-list';
    import calHeight from '/src/mixins/cal-table-height';
    import { pageConfig } from '/src/utils/jk/jk-tool';
    import getMenuColumn from '../../../mixins/getMenuColumn';
    import handlerCache from '../../../mixins/handler-cache';
    import { spinReport } from '../../../api/production/reports';

    export default {
        name: 'SpinReport',
        components: {
        },
        mixins: [calHeight, getMenuColumn, handlerCache],
        data() {
            return {
                apiItem: {
                    'page': spinReport
                },
                typeList: [
                    { id: 0, name: '当前空锭' },
                    { id: 1, name: '当前弱捻' },
                    { id: 2, name: '普坏锭' },
                    { id: 3, name: '开车坏锭' },
                    { id: 4, name: '班次坏锭' }
                ],
                importDialogState: false,
                auditStateList: auditStateList,
                dataId: null,
                tableLoading: true,
                exportLoading: false,
                tableData: [],
                searchParams: {
                    count: 0,
                    pageNo: pageConfig.pageNo,
                    pageSize: pageConfig.pageSize,
                    totalTime: null,
                    type: 0
                    // ifDebug: true
                }
            };
        },
        methods: {
            setPh(type) {
                let str = '';
                if (type === 0) {
                    str = '分钟';
                } else if (type === 1) {
                    str = '小时';
                } else if (type === 2) {
                    str = '小时';
                } else if (type === 3) {
                    str = '班次个数';
                } else if (type === 4) {
                    str = '次数';
                }
                return str;
            },
            onVisibleChangeOfImportDialog(e) {
                this.importDialogState = e;
            },
            onFinishBtnOfImportDialog() {
                this.importDialogState = false;
                this.getListRequest();
            },
            onPageChange(pageIndex, pageSize) {
                this.searchParams.pageNo = pageIndex;
                this.searchParams.pageSize = pageSize;
                this.getListRequest();
            },
            /** 查询列表 */
            getListRequest() {
                const params = JSON.parse(JSON.stringify(this.searchParams));
                if ([2, 3, 4].includes(params.type)) {
                    params.worstTimes = params.totalTime;
                    delete params.totalTime;
                }
                this.tableLoading = true;
                this.apiItem.page(params).then(res => {
                    this.tableLoading = false;
                    if (res.data.status === 200) {
                        this.tableData = res.data.res;
                        this.searchParams.count = res.data.count;
                    }
                });
            },
            /** 搜索按钮操作 */
            onSearchBtn() {
                this.searchParams.pageNo = 1;
                this.searchParams.count = 1;
                this.getListRequest();
            },

            /** 删除按钮操作 */
            onDeleteBtn(row) {
                this.apiItem.delete({ id: row.id }).then((res) => {
                    if (res.data.status === 200) {
                        this.getListRequest();
                        this.$tipsBar(this, 'delete');
                    }
                }).catch(() => {});
            },
            clearCacheMethod() {
                // Object.assign(this.$data, this.$options.data());
                this.$nextTick(() => {
                    this.getDependentData();
                });
            },
            async getDependentData() {
                await this.getMenuColumnListRequest();
                await this.getListRequest();
            }
        },
        mounted() {
            this.getDependentData();
        }
    };
</script>
